/*
 * Scenarios.java
 *
 * Created on September 27, 2007, 8:06 PM
 *
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.fpdev.core;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * Map-based collection of Scenarios associated with a DataPackage.
 * 
 * @author demory
 * @see Scenario
 * @see DataPackage
 */
public class Scenarios {

  private Map<Short, Scenario> map_;
  private Scenario base_;

  /** Creates a new instance of Scenarios */
  public Scenarios() {
    map_ = new HashMap<Short, Scenario>();
    
    // create the base scenario
    add(new Scenario((short) 1, "Base", null));
  }

  public void add(Scenario s) {
    if (map_.isEmpty()) {
      base_ = s;
    }
    map_.put(s.getID(), s);
  }

  public Scenario get(int i) {
    return map_.get((short) i);
  }

  public Scenario get(short i) {
    return map_.get(i);
  }

  public Scenario getFromName(String name) {
    Iterator<Scenario> iter = getScenarios();
    while (iter.hasNext()) {
      Scenario s = iter.next();
      if (s.getName().equals(name)) {
        return s;
      }
    }
    return null;
  }

  public Iterator<Scenario> getScenarios() {
    return map_.values().iterator();
  }

  public Scenario getBase() {
    return base_;
  }
}
